package com.linghang.wusthelper.controller.library;

import com.linghang.wusthelper.annotation.AuthenToken;
import com.linghang.wusthelper.common.ServerResponse;
import com.linghang.wusthelper.service.LibraryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author origin
 * 图书馆controller
 */
@RestController
@RequestMapping("/lib")
public class LibraryController {

    @Autowired
    private LibraryService libraryService;

    //  图书馆登陆
    @PostMapping(value = "/login")
    @AuthenToken
     public ServerResponse login(@RequestHeader(value = "token",required = true) String token,
                                 @RequestParam(value = "password",required = true) String password){
        return libraryService.login(token,password);
     }

     //  获取当前借阅记录
     @GetMapping(value = "/getrentinfo")
     @AuthenToken
     public ServerResponse getRentInfo(@RequestHeader(value = "token",required = true) String token) throws InterruptedException {
        return libraryService.getRentInfo(token);
     }

     //  获取借阅历史
     @GetMapping(value = "getrenthistory")
     @AuthenToken
     public ServerResponse getRenthistory(@RequestHeader(value = "token",required = true) String token) throws InterruptedException {
        return libraryService.getRentHistory(token);
     }

     //  获取图书信息
     @GetMapping(value = "getbookinfo")
     public ServerResponse getBookInfo(@RequestParam(value = "bookUrl",required = true) String bookUrl) throws InterruptedException {
        return libraryService.getBookInfo(bookUrl);
     }

     //  获取图书馆公告
     @GetMapping("/getannouncementlist")
     public ServerResponse getAnnouncementList(@RequestParam(value = "pageNum",required = true,defaultValue = "1") int pageNum,
                                           @RequestParam(value = "pageSize",required = false,defaultValue = "10") int pageSize){
        return libraryService.getAnnouncementList(pageNum,pageSize);
     }

     //  获取公告内容
     @GetMapping("/getannouncementcontent")
     public ServerResponse getAnnouncementContent(@RequestParam(value = "announcementId") int announcementId){
        return libraryService.getAnnouncementContent(announcementId);
     }
}
